package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.CompanyDao;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CompanyImpl implements CompanyDao {
    @Override
    public CompanyModel getCompanyModel() {
        String sql = "select * from company where is_show=1";
        List<CompanyModel> list = setList(sql);
        return list.size() > 0 ? list.get(0) : null;
    }

    private List<CompanyModel> setList(String sql) {
        ResultSet resultSet = JDBC.query(sql);
        List<CompanyModel> list = new ArrayList<>();
        try {
            while (resultSet.next()) {
                CompanyModel model = new CompanyModel();
                model.setId(resultSet.getInt("id"));
                model.setAddress(resultSet.getString("address"));
                model.setCreateTime(resultSet.getString("create_time"));
                model.setEmail(resultSet.getString("email"));
                model.setEnable(resultSet.getInt("enable"));
                model.setPhone(resultSet.getString("phone"));
                model.setLogo(resultSet.getString("logo"));
                model.setLinePhone(resultSet.getString("line_phone"));
                model.setVersion(resultSet.getString("version"));
                list.add(model);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
//            JDBC.close();
        }
        return list;
    }
}
